/*
 * @Author: cl
 * @Description: 网络请求拦截器
 * @Date: 2023-04-11 09:07:31
 * @LastEditTime: 2023-04-11 09:59:07
 * @FilePath: \jsnode\nestjs\naota\src\common\response.ts
 * @LastEditors: cl
 */

import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'
import { Observable, map } from 'rxjs'

interface data<T> {
  data: T
}
@Injectable()
export class Response<T = any> implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler<any>): Observable<data<T>> {
    return next.handle().pipe(
      map((data) => {
        return {
          data,
          status: 0,
          message: '成功',
        }
      }),
    )
  }
}
